package network.protocol;

import java.io.Serializable;

/**
 * 
 * @author Erik
 *A package that contains all necessary data for
 *sync the population in the buildings
 */

@SuppressWarnings("serial")
public class syncBuildingsPopPackage implements Serializable {
	//buildingID
	private int building;
	//population in the building with buildingID
	private int pop;
	
	
	public syncBuildingsPopPackage(int building, int pop){
		this.building = building;
		this.pop = pop;
	}
	
	/**
	 * convert a correct formated string to a syncBuildingsPopPackage
	 * format: building(int) + \n + pop(int) + \n
	 * @param data
	 */
	public syncBuildingsPopPackage(String data){
		int start = 0, end = 0;
		
		end = data.indexOf('\n', start);	
		building = Integer.parseInt(data.substring(start, end));
		start = end + 1;
		
		end = data.indexOf('\n', start);	
		pop = Integer.parseInt(data.substring(start, end));
		start = end + 1;
	}
	
	/**
	 * convert the syncBuildingsPopPackage to a correct formated String
	 * @return String
	 */
	
	public String toPackage(){
		StringBuffer res = new StringBuffer();
		res.append(building);
		res.append('\n');
		
		res.append(pop);
		res.append('\n');

		return res.toString();
	}
	
	public int getBuilding(){
		return building;
	}
	
	public int getPop(){
		return pop;
	}
}
